enable reading server uri from env var #3891
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The managed database configuration is a nice feature for further improving the value provided by sqlc. The server connection string however must be specified in
sqlc.yaml
, which limits the flexibility of an sqlc project to adapt to multiple environments.I have a project which utilizes sqlc in local development. I would like to also utilize sqlc in Continuous Integration of that project. The CI server in question is configured in a way which makes me unable to provide a connection string which can be reused in both local development and CI.
Many other populate cli tools accepts configuration through environment variables or flags, making them more flexible and therefore easier to integrate into situations like mine. One example being
atlas migrate lint
which operates in much the same way assqlc verify
andsqlc vet
, where a database server is used to validate sql.This PR adds the possibility to configure the server uri through an environment variable if the
sqlc.yaml
contains only one server.I am happy to receive feedback or alternative solutions.
Thanks 🙏
Expand me if you'd like to learn why I am unable to provide a static connection string
The CI server is configured such that jobs is executed in docker containers. One invocation of my CI pipeline is executed in one such container. The docker socket of the host is mounted into that docker container. My CI pipeline starts by starting a postgres database server in a docker container and mounts the container port 5432 onto port 55432 on the host, such that
sqlc
should be able to connect tolocalhost:55432
. The problem is that the host of the container is the CI server and not the container my CI pipeline is executing in.sqlc
is therefore unable to connect to the database server.